package com.example.service.impl;

import com.example.dao.BookDao;
import com.example.dao.BorrowDao;
import com.example.entity.Book;
import com.example.entity.Borrow;
import com.example.service.BookService;
import com.example.service.BorrowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @desc:
 * @author: maomaostudent
 * @date: 2023/10/28 12:05
 */
@Service
@Slf4j
public class BorrowServiceImpl implements BorrowService {
    @Autowired
    private BorrowDao borrowDao;
    @Autowired
    private BookDao bookDao;
    @Transactional
    @Override
    public int borrowBook(int book_id, int user_id) {
        //1.查询书本id
        //Book book =  bookDao.queryById(book_id);
        //2.获取借阅时间
        Borrow borrow = new Borrow();
        borrow.setBorrow_date(new Date());
        return borrowDao.borrowBook(book_id,user_id);

    }


    @Override
    @Transactional
    public int returnBook(int book_id, int user_id) {
        return borrowDao.returnBook(book_id,user_id);
    }

}
